package com.gxa.usermanagement.service.impl;

import com.gxa.common.R;
import com.gxa.common.entity.usermange.Merchant;
import com.gxa.usermanagement.mapper.LoginMapper;
import com.gxa.usermanagement.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    @Override
    public R loginService(String userName, String passWord) {
        R r = new R();
        List<Merchant> merchants = loginMapper.loginMapper(userName, passWord);

        if(merchants.size() ==0){
            r.setCode(500);
            r.setMessage("密码或用户名错误");
        }else {
            for (Merchant merchant : merchants) {
                merchant.setMerchantPassword("NULL");
            }
            r.setData(merchants);
            r.setCode(200);
            r.setMessage("操作成功");
        }

        return r;
    }

    @Override
    public R updatePassWordService(String phone, String passWord) {
        Integer integer = loginMapper.updatePassWordMapper(phone, passWord);
        R r = new R();
        r.setCode(200);
        r.setMessage("操作成功");
        return r;
    }

    @Override
    public R auditPassWordService(String phone) {

        R r = new R();
        r.setCode(200);
        r.setMessage("已设置密码");
        r.setData(loginMapper.auditPassWordMapper(phone));
        return r;
    }
}
